# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/6/3 14:47
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : interval_task_scheduleing.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""


def max_interval_schedule(job_list):
    job_schedule = []
    job_num = len(job_list)
    job_list.sort(key=lambda x: x[2])  # 按照结束时间从小到大进行排序
    for i in range(job_num):
        if not job_schedule:
            job_schedule.append(job_list[i])
        else:
            # 调度列表最后一任务结束时间早于任务日程列表开始时间，不冲突
            if job_schedule[-1][2] <= job_list[i][1]:
                job_schedule.append(job_list[i])
    return job_schedule


if __name__ == '__main__':
    # 每一项任务表示为[任务号，开始时间，结束时间]
    jobs = [['e', 8, 10], ['b', 2, 5], ['c', 4, 7], ['a', 1, 3], ['d', 6, 9]]
    print(max_interval_schedule(jobs))
#     [['a', 1, 3], ['c', 4, 7], ['e', 8, 10]]
